<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    

    <script>
        class Promise{
            promiseState = 'ing'    //状态
            promiseResult = null    //数据

            constructor(callback){       //构造器
                // let callback = (resolve,reject) => {
                //     console.log('执行')
                //     resolve(11)
                //     reject(22)
                // }
                const resolve = (data)=>{
                    if(this.promiseState !=='ing')return
                    this.promiseState = 'success'
                    this.promiseResult = data
                }
                const reject = (data)=>{
                    if(this.promiseState !=='ing')return
                    this.promiseState = 'error'
                    this.promiseResult = data
                }
                callback(resolve,reject)
            }
        }
        Promise.prototype.then = function(fn1,fn2){
            if(this.promiseState === 'success'){
                fn1(this.promiseResult)
            }
            if(this.promiseState === 'error'){
                fn2(this.promiseResult)
            }
        }

        Promise.prototype.then = function(){}
        Promise.prototype.catch = function(){}
        Promise.prototype.finally = function(){}

        Promise.resolve = function(){}
        Promise.reject = function(){}
        Promise.all = function(){}
        Promise.race = function(){}
        Promise.allSettled = function(){}
        Promise.any = function(){}


        const p = new Promise((resolve,reject) => {
            console.log('执行')
            resolve(11)
            reject(22)
        })
        console.log(p)
        

        p
        .then(
            res => {
                console.log('res',res);
            },
            err => {
                console.log('err',err);
            }
        )
    </script>
</body>
</html>